package com.msf.modules.sys.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.msf.common.domain.vo.Result;
import com.msf.common.exception.MfsException;
import com.msf.modules.sys.domain.vo.MenuOption;
import com.msf.modules.sys.domain.vo.SysPermissionTree;
import com.msf.modules.sys.domain.vo.TreeModel;
import com.msf.modules.sys.entity.SysPermission;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 菜单权限表 服务类
 * </p>
 *
 * @author author
 * @since 2024-10-09
 */
public interface ISysPermissionService extends IService<SysPermission> {

    Result<List<MenuOption>> listAll(String keywords, HttpServletRequest req);

    Result<List<SysPermissionTree>> lists(String keywords);

    Result<List<SysPermissionTree>> getSystemMenuList();

    Result<List<SysPermissionTree>> getSystemSubmenu(String parentId);

    Result<?> getSystemSubmenuBatch(String parentIds);

    Result<?> getUserPermissionByToken(HttpServletRequest request);

    Result<?> getPermCode();

    Result<SysPermission> add(SysPermission permission);

    Result<SysPermission> edit(SysPermission permission);

    Result<String> checkPermDuplications(String id, String url, Boolean alwaysShow);

    Result<?> delete(String id);

    Result<?> deleteBatch(String ids);

    Result<Map<String, Object>> queryTreeList();

    Result<List<TreeModel>> queryAsync(String parentId);

    /**
     * 通过父id查询菜单
     *
     * @param parentId 父id
     */
    public List<TreeModel> queryListByParentId(String parentId);

    /**
     * 逻辑删除
     *
     * @param id 菜单id
     */
    public void deletePermissionLogical(String id) throws MfsException;

    /**
     * 添加菜单
     *
     * @param sysPermission SysPermission对象
     */
    public void addPermission(SysPermission sysPermission) throws MfsException;

    /**
     * 编辑菜单
     *
     * @param sysPermission SysPermission对象
     */
    public void editPermission(SysPermission sysPermission) throws MfsException;

    /**
     * 获取登录用户拥有的权限
     *
     * @param username 用户名
     */
    public List<SysPermission> queryByUser(String username);

    /**
     * 查询出带有特殊符号的菜单地址的集合
     *
     */
    public List<String> queryPermissionUrlWithStar();

    /**
     * 判断用户否拥有权限
     *
     */
    public boolean hasPermission(String username, SysPermission sysPermission);

    /**
     * 根据用户和请求地址判断是否有此权限
     */
    public boolean hasPermission(String username, String url);

    /**
     * 查询部门权限数据
     *
     */
    List<SysPermission> queryDepartPermissionList(String departId);

    /**
     * 检测地址是否存在(聚合路由的情况下允许使用子菜单路径作为父菜单的路由地址)
     *
     * @param alwaysShow 是否是聚合路由
     */
    boolean checkPermDuplication(String id, String url, Boolean alwaysShow);
}
